$(function(){
	$('#activity').html('');
	loadHotActivity(0,15,0);
});

 
function loadCareActivity(){
	$('#activity').html('');
	//loadActivity(1,0,15,3)
	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/classTopicSearch',
			data: {
				topic_type:3,
				pos_idx:0,
				count:15,
			},
			success:function(data){
				console.log(JSON.stringify(data.data));
				if(data.code==200){
					var result='';
					for(var i=0;i<data.data.length;i++){
						result=Common.buildTopic(data);
//						var cover_pic='';
//						//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
//						if(data.data[i].cover_pic ==''){
//							if(data.data[i].pic_list==''){
//								cover_pic="images/nopic.jpg";
//							}else{
//								cover_pic=data.data[i].pic_list[0];
//							}
//							
//						}else{
//							cover_pic=data.data[i].cover_pic;
//						}
//				
//						result+='<div class="ibox-content">';
//						result+='<div class="row">';
//						result+='<div class="col-md-3">';
//		                result+='</div >';
//		                result+='<div class="col-md-9" >';
//						result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
//	                    result+='<h2>';
//	                    if(data.data[i].is_top==1){
//	                    	result+='<button class="btn btn-danger" type="button">置顶</button>';
//	                    }
//	                    result+=data.data[i].title+'</h2>';
//	               		result+='</a>';
//	                    result+='<div class="small m-b-xs text-right ">';
//	                    result+='<span class="text-muted"><i class="fa fa-clock-o"></i>'+data.data[i].create_time+'</span> ';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='<div class="row">';
//	                    result+='<div class="col-md-3" > <img  class="img-responsive" src="'+cover_pic+'"></div>';
//	                    result+='<br>';
//	                    result+='<div class="col-md-9" ><p>'+data.data[i].indroduce+'</p> </div>';
//	                    result+='</div>';
//	                    result+='<div class="row m-t-sm ">';
//	                    result+='<div class="col-md-3">';
//	                    result+='</div >';
//	                    result+='<div class="col-md-9">';
//	                    result+='<div class="col-md-2 text-center">  ';
//	                    result+='<button class="btn btn-success btn-xs" type="button">'+data.data[i].class_name+'</button>';
//	                    result+='</div>';
//	                    result+='<div class="col-md-2 text-center"><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
//	                    result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button">';
//	                    result+='<i class="fa fa-external-link">'+data.data[i].forward_cnt+'转发 </i>';
//	                    result+='</button></a></div>';
//	                    result+='<div class="col-md-2 text-center "><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">'; 
//	                    result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button" > ';
//	                    result+='<i class="fa fa-commenting-o">'+data.data[i].comment_cnt+'评论</i>   ';
//	                    result+='</button></a></div>';
//	                    result+='<div class="col-md-2 text-center " >'; 
//	                    if(data.data[i].is_thumbs==0){//用户已经点赞
//	                    	result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button"><i class="fa fa-thumbs-o-up" style="color:red">'+data.data[i].thumbs_cnt+'点赞 </i>  '; 
//	                    }else{//用户还未点赞
//	                    	result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button" onclick="topicthumbsUp('+data.data[i].topic_id+',2)" ><i class="fa fa-thumbs-o-up"   >'+data.data[i].thumbs_cnt+'点赞 </i> ';
//	                    }
//	                    result+='</button></div>';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='</div>';
					}
					if(data.data.length>=15){
						result+='<button class="btn btn-primary btn-block m " id="load_care_data_button" onclick="loadCareActivityData()"><i class="fa fa-arrow-down"></i> 显示更多</button>';
					}else{
						result+='<button class="btn btn-primary btn-block m"> 没有更多消息</button>';
					}
					
					$('#activity').append(result);
				}
			},
			error:function(data){
			}
	    });
}

function loadCareActivityData(){
	$('#load_care_data_button').remove();
	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/classTopicSearch',
			data: {
				topic_type:3,
				pos_idx:$('#activity').children().length,
				count:15,
			},
			success:function(data){
				console.log(JSON.stringify(data.data));
				if(data.code==200){
					var result='';
					for(var i=0;i<data.data.length;i++){
//						var cover_pic='';
//						//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
//						if(data.data[i].cover_pic ==''){
//							if(data.data[i].pic_list==''){
//								cover_pic="images/nopic.jpg";
//							}else{
//								cover_pic=data.data[i].pic_list[0];
//							}
//							
//						}else{
//							cover_pic=data.data[i].cover_pic;
//						}
//				
//						result+='<div class="ibox-content">';
//						result+='<div class="row">';
//						result+='<div class="col-md-3">';
//		                result+='</div >';
//		                result+='<div class="col-md-9" >';
//						result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
//	                    result+='<h2>';
//	                    if(data.data[i].is_top==1){
//	                    	result+='<button class="btn btn-danger" type="button">置顶</button>';
//	                    }
//	                    result+=data.data[i].title+'</h2>';
//	               		result+='</a>';
//	                    result+='<div class="small m-b-xs text-right ">';
//	                    result+='<span class="text-muted"><i class="fa fa-clock-o"></i>'+data.data[i].create_time+'</span> ';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='<div class="row">';
//	                    result+='<div class="col-md-3" > <img  class="img-responsive" src="'+cover_pic+'"></div>';
//	                    result+='<br>';
//	                    result+='<div class="col-md-9" ><p>'+data.data[i].indroduce+'</p> </div>';
//	                    result+='</div>';
//	                    result+='<div class="row m-t-sm ">';
//	                    result+='<div class="col-md-3">';
//	                    result+='</div >';
//	                    result+='<div class="col-md-9">';
//	                    result+='<div class="col-md-2 text-center">  ';
//	                    result+='<button class="btn btn-success btn-xs" type="button">'+data.data[i].class_name+'</button>';
//	                    result+='</div>';
//	                    result+='<div class="col-md-2 text-center"><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
//	                    result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button">';
//	                    result+='<i class="fa fa-external-link">'+data.data[i].forward_cnt+'转发 </i>';
//	                    result+='</button></a></div>';
//	                    result+='<div class="col-md-2 text-center "><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">'; 
//	                    result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button" > ';
//	                    result+='<i class="fa fa-commenting-o">'+data.data[i].comment_cnt+'评论</i>   ';
//	                    result+='</button></a></div>';
//	                    result+='<div class="col-md-2 text-center " >'; 
//	                    if(data.data[i].is_thumbs==0){//用户已经点赞
//	                    	result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button"><i class="fa fa-thumbs-o-up" style="color:red">'+data.data[i].thumbs_cnt+'点赞 </i>  '; 
//	                    }else{//用户还未点赞
//	                    	result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button" onclick="topicthumbsUp('+data.data[i].topic_id+',2)" ><i class="fa fa-thumbs-o-up"   >'+data.data[i].thumbs_cnt+'点赞 </i> ';
//	                    }
//	                    result+='</button></div>';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='</div>';
						result=Common.buildTopic(data);
					}
					if(data.data.length>=15){
						result+='<button class="btn btn-primary btn-block m " id="load_care_data_button" onclick="loadCareActivityData()"><i class="fa fa-arrow-down"></i> 显示更多</button>';
					}else{
						result+='<button class="btn btn-primary btn-block m"> 没有更多消息</button>';
					}
					
					$('#activity').append(result);
				}
			},
			error:function(data){
			}
	    });
}

function loadNewActivity(){
	$('#activity').html('');
	loadActivity(3,0,15,3)
}
function loadHot(pos_idx1,count1,type){
	$('#activity').html('');
	loadHotActivity(pos_idx1,count1,type);
}

function loadHotActivity(pos_idx1,count1,type){
 
	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/hotActivity',
			data: {
				type:type,
				pos_idx:pos_idx1,
				count:count1,
			},
			success:function(data){
				console.log(JSON.stringify(data.data));
				if(data.code==200){
					var result='';
					for(var i=0;i<data.data.length;i++){
//						var cover_pic='';
//						//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
//						if(data.data[i].cover_pic ==''){
//							if(data.data[i].pic_list==''){
//								cover_pic="images/nopic.jpg";
//							}else{
//								cover_pic=data.data[i].pic_list[0];
//							}
//							
//						}else{
//							cover_pic=data.data[i].cover_pic;
//						}
//				
//						result+='<div class="ibox-content">';
//						result+='<div class="row">';
//						result+='<div class="col-md-3">';
//		                result+='</div >';
//		                result+='<div class="col-md-9" >';
//						result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
//	                    result+='<h2>';
//	                    if(data.data[i].is_top==1){
//	                    	result+='<button class="btn btn-danger" type="button">置顶</button>';
//	                    }
//	                    result+=data.data[i].title+'</h2>';
//	               		result+='</a>';
//	                    result+='<div class="small m-b-xs text-right ">';
//	                    result+='<span class="text-muted"><i class="fa fa-clock-o"></i>'+data.data[i].create_time+'</span> ';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='<div class="row">';
//	                    result+='<div class="col-md-3" > <img  class="img-responsive" src="'+cover_pic+'"></div>';
//	                    result+='<br>';
//	                    result+='<div class="col-md-9" ><p>'+data.data[i].indroduce+'</p> </div>';
//	                    result+='</div>';
//	                    result+='<div class="row m-t-sm ">';
//	                    result+='<div class="col-md-3">';
//	                    result+='</div >';
//	                    result+='<div class="col-md-9">';
//	                    result+='<div class="col-md-2 text-center">  ';
//	                    result+='<button class="btn btn-success btn-xs" type="button">'+data.data[i].class_name+'</button>';
//	                    result+='</div>';
//	                    result+='<div class="col-md-2 text-center"><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
//	                    result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button">';
//	                    result+='<i class="fa fa-external-link">'+data.data[i].forward_cnt+'转发 </i>';
//	                    result+='</button></a></div>';
//	                    result+='<div class="col-md-2 text-center "><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">'; 
//	                    result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button" > ';
//	                    result+='<i class="fa fa-commenting-o">'+data.data[i].comment_cnt+'评论</i>   ';
//	                    result+='</button></a></div>';
//	                    result+='<div class="col-md-2 text-center " >'; 
//	                    if(data.data[i].is_thumbs==0){//用户已经点赞
//	                    	result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button"><i class="fa fa-thumbs-o-up" style="color:red">'+data.data[i].thumbs_cnt+'点赞 </i>  '; 
//	                    }else{//用户还未点赞
//	                    	result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button" onclick="topicthumbsUp('+data.data[i].topic_id+',2)" ><i class="fa fa-thumbs-o-up"   >'+data.data[i].thumbs_cnt+'点赞 </i> ';
//	                    }
//	                    result+='</button></div>';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='</div>';
						result=Common.buildTopic(data);
					}
					if(data.data.length>=15){
						result+='<button class="btn btn-primary btn-block m " id="load_hot_data_button" onclick="loadHotActivityData('+type+')"><i class="fa fa-arrow-down"></i> 显示更多</button>';
					}else{
						result+='<button class="btn btn-primary btn-block m"> 没有更多消息</button>';
					}
					
					$('#activity').append(result);
				}
			},
			error:function(data){
			}
	    });
	
}



function loadActivity(type,pos_idx1,count1,topic_type1){
	
	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/homepagetopicSearch ',
			data: {
				type:type,//0 推荐预览查询 1关注预览差查询	2热门预览查询 3最新预览查询
				pos_idx:pos_idx1,
				count:count1,
				topic_type:topic_type1//0-普通话题 1-投票 2-问卷调查 3-活动管理
			},
			success:function(data){
				console.log(JSON.stringify(data.data));
				if(data.code==200){
					var result='';
					for(var i=0;i<data.data.length;i++){
						var cover_pic='';
						//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
						if(data.data[i].cover_pic ==''){
							if(data.data[i].pic_list==''){
								cover_pic="images/nopic.jpg";
							}else{
								cover_pic=data.data[i].pic_list[0];
							}
							
						}else{
							cover_pic=data.data[i].cover_pic;
						}
				
						result+='<div class="ibox-content">';
						result+='<div class="row">';
						result+='<div class="col-md-3">';
		                result+='</div >';
		                result+='<div class="col-md-9" >';
						result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
	                    result+='<h2>';
	                    if(data.data[i].is_top==1){
	                    	result+='<button class="btn btn-danger" type="button">置顶</button>';
	                    }
	                    result+=data.data[i].title+'</h2>';
	               		result+='</a>';
	                    result+='<div class="small m-b-xs text-right ">';
	                    result+='<span class="text-muted"><i class="fa fa-clock-o"></i>'+data.data[i].create_time+'</span> ';
	                    result+='</div>';
	                    result+='</div>';
	                    result+='</div>';
	                    result+='<div class="row">';
	                    result+='<div class="col-md-3" > <img  class="img-responsive" src="'+cover_pic+'"></div>';
	                    result+='<br>';
	                    result+='<div class="col-md-9" ><p>'+data.data[i].indroduce+'</p> </div>';
	                    result+='</div>';
	                    result+='<div class="row m-t-sm ">';
	                    result+='<div class="col-md-3">';
	                    result+='</div >';
	                    result+='<div class="col-md-9">';
	                    result+='<div class="col-md-2 text-center">  ';
	                    result+='<button class="btn btn-success btn-xs" type="button">'+data.data[i].class_name+'</button>';
	                    result+='</div>';
	                    result+='<div class="col-md-2 text-center"><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
	                    result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button">';
	                    result+='<i class="fa fa-external-link">'+data.data[i].forward_cnt+'转发 </i>';
	                    result+='</button></a></div>';
	                    result+='<div class="col-md-2 text-center "><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">'; 
	                    result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button" > ';
	                    result+='<i class="fa fa-commenting-o">'+data.data[i].comment_cnt+'评论</i>   ';
	                    result+='</button></a></div>';
	                    result+='<div class="col-md-2 text-center " >'; 
	                    if(data.data[i].is_thumbs==0){//用户已经点赞
	                    	result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button"><i class="fa fa-thumbs-o-up" style="color:red">'+data.data[i].thumbs_cnt+'点赞 </i>  '; 
	                    }else{//用户还未点赞
	                    	result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button" onclick="topicthumbsUp('+data.data[i].topic_id+',2)" ><i class="fa fa-thumbs-o-up"   >'+data.data[i].thumbs_cnt+'点赞 </i> ';
	                    }
	                    result+='</button></div>';
	                    result+='</div>';
	                    result+='</div>';
	                    result+='</div>';
					}
					if(data.data.length>=15){
						result+='<button class="btn btn-primary btn-block m " id="load_data_button" onclick="loadData('+type+')"><i class="fa fa-arrow-down"></i> 显示更多</button>';
					}else{
						result+='<button class="btn btn-primary btn-block m"> 没有更多消息</button>';
					}
					
					$('#activity').append(result);
				}
			},
			error:function(data){
			}
	    });
}

function loadData(type){
	$('#load_data_button').remove();
	loadActivity(type,$('#activity').children().length,15,3);
}

function loadHotActivityData(type){
	$('#load_hot_data_button').remove();
	loadHotActivity(type,$('#activity').children().length,15,0);
}

